package com.think.admin.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * <p>
 * mybatisplus：配置类
 * </p>
 *
 * @author: xwj
 * @data: 2019-04-07
 */
@MapperScan(basePackages = {"com.think.admin.web.mapper*"})
@MapperScan(basePackages = {"com.think.admin.wxWeb.mapper*"})
@Configuration
public class MybatisPlusConfig {
    /**
     * 分页插件
     *
     * @return com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
     * @author xwj
     * @data 2019/4/7
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    /**
     * SQL执行效率插件
     *
     * @return com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor
     * @author xwj
     * @data 2019/4/7
     */
    @Bean
    @Profile({"dev", "test"})// 设置dev环境开启
    public PerformanceInterceptor performanceInterceptor() {
        return new PerformanceInterceptor();
    }

    /**
     * 自动填充
     *
     * @return com.think.admin.config.AdminMetaObjectHandler
     * @author xwj
     * @data 2019/4/7
     */
    @Bean
    public AdminMetaObjectHandler adminMetaObjectHandler() {
        return new AdminMetaObjectHandler();
    }

    /**
     * 逻辑删除
     *
     * @return com.baomidou.mybatisplus.core.injector.ISqlInjector
     * @author xwj
     * @data 2019/4/7
     */
    @Bean
    public ISqlInjector sqlInjector() {
        return new LogicSqlInjector();
    }
}
